package edu.friday.repository.custom.impl;

import edu.friday.repository.custom.SysRoleCustomRepository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

public class SysRoleCustomRepositoryImpl implements SysRoleCustomRepository {
    @PersistenceContext
    private EntityManager entityManager;


    @Override
    public int batchInsertUserRole(Long[] roleIds, Long[] menus) {
        int length=roleIds.length >menus.length?menus.length:roleIds.length;
        StringBuffer sql=new StringBuffer();
        sql.append("insert into sys_role_menu(role_id,menu_id) values");
        Query query=entityManager.createNativeQuery(sql.toString());
        int paramIndex=1;
        for (int i = 0; i < length; i++) {
            query.setParameter(paramIndex++,roleIds[i]);
            query.setParameter(paramIndex++,menus[i]);

        }
        return query.executeUpdate();
    }
}
